#include <string>
#include <vector>
using namespace std;

//字符串转换整数(atoi)
class Solution {
public:
    int myAtoi(string s) {
        int flag = true;
        long long res = 0;
        int index = 0;
        //越过前导空格
        while (' ' == s[index])
            ++index;
        for (int i = index;i < s.length();++i)
        {
            if ('-' == s[i] || '+' == s[i])
            {
                if (index == i)
                {
                    if ('-' == s[i])
                        flag = false;
                    else
                        continue;
                }
                else
                    goto back;
            }
            else if (s[i] >= '0' && s[i] <= '9')
            {
                res = res * 10 + s[i] - '0';
                if (flag && res > INT_MAX)
                    return INT_MAX;
                else if (!flag && -res < INT_MIN)
                    return INT_MIN;
            }
            else //碰见字母、.、空格这些字符直接返回
                goto back;
        }
    back:
        return true == flag ? res : -res;
    }
};

//只出现一次的数字III
class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        int n = 0;
        for(const auto& num:nums)
        n ^= num;
        int judge = 1;
        while(!(n & judge))
        {
            judge = judge << 1;
        }//或者judge 直接等于 num & -num
        //进行分组
        vector<int> res(2,0);
        for(const auto& num:nums)
        {
            if(judge & num)
            res[0] ^= num;
            // else
            // res[1] ^= num;
        }
        res[1] = n ^ res[0];
        return res;
    }
};

